home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / pasclib.arc / PASCLIB.DOC next >
Encoding:
Text File  |  1985-06-28  |  13.7 KB  |  370 lines

  1.  
  2.  
  3.                      PASCLIB Version 1.0 (Copyright 1985)
  4.     =======================================================================
  5.                         by:  Gerry L. Kilgore
  6.                              1725 Kellogg Springs Dr.
  7.                              Dunwoody, GA 30338
  8.                              (404) 396-6107 (Voice)
  9.     =======================================================================
  10.  
  11.     PASCLIB is a library of floating point subroutines, a sine/cosine sub-
  12.     routine, a random number function and a ramdomize program to seed the
  13.     random number generator.
  14.  
  15.     The library was written in Assembler language primarily to interface
  16.     with IBM/MS Pascal programs to obtain great speed without giving up
  17.     single precision accuracy such as required by graphics programs using
  18.     mathematical functions or plotting.  Other applications, not requiring
  19.     the accuracy of long precision can, of course, benefit from use of this
  20.     library.
  21.  
  22.     WHY BOTHER??  Simply put, because they perform approximately five (5)
  23.     times faster that the equivalent operations using short precision in
  24.     IBM/MS Pascal.  They are not hampered by generalized overhead.
  25.  
  26.     The library is equally useable by Assembler Language programmers.  In
  27.     fact, it was constructed with a separate EXTERNAL interface which, in
  28.     turn, calls the INTERNAL routines.  The Assembler Language programmer
  29.     can bypass the EXTERNAL interface and go directly to the INTERNAL
  30.     routines, if he obtains the A/L source.  If not, he may still use the
  31.     EXTERNAL calls.
  32.  
  33.     I am declaring this program in the Public Domain under the Freeware
  34.     Concept.  That is, you are free to copy and distribute this library
  35.     as long as you do so without financial gain.  If you find it useful,
  36.     and feel that it is justified, this author will not turn down any 
  37.     contributions ($20.00 is reasonable).  For your contribution of at
  38.     least $20.00 along with a self-addressed diskette mailer with return
  39.     postage affixed, I will send you a diskette with the commented 
  40.     Assembler Language source of PASCLIB, additional documentation on how
  41.     to call the internal routines, and I will put you on my mailing
  42.     list for notification of fixes, enhancements and upgrades.  Send
  43.     contributions to the address shown above.
  44.  
  45.     DISCLAIMER:  This author will not be held accountable for any
  46.     problems or damages associated with the use of PASCLIB whether they
  47.     be physical, financial or psychological.  If you use PASCLIB, you
  48.     use it at your own risk!
  49.  
  50.     ======================================================================
  51.  
  52.  
  53.                           WHAT'S IN THE PACKAGE?
  54.                           ======================
  55.  
  56.     You have:
  57.                PASCLIB.INC   - the "INCLUDE" file for IBM/MS Pascal
  58.                PASCLIB.OBJ   - the subroutine object module.
  59.                PASCLIB.DOC   - this documentation.
  60.  
  61.     In IBM/MS Pascal, you must place an "INCLUDE" statement in your
  62.     program as if you were defining a function or procedure.  This will
  63.     permit you to invoke the Functions and Procedures of PASCLIB.OBJ.
  64.     That statement will be as follows:
  65.  
  66.     {$INCLUDE:'PASCLIB.INC'}
  67.  
  68.     with no semi-colon following the statement.  You may, of course, pre-
  69.     cede the name, PASCLIB.INC, with a drive specifier, such as,
  70.  
  71.     {$INCLUDE:'B:PASCLIB.INC'}
  72.  
  73.     if PASCLIB.INC is not on the default drive.
  74.  
  75.     PASCLIB.INC contains the following external procedure and function
  76.     definitions:
  77.  
  78.         procedure randomize; external;
  79.         function random ( n : integer): integer; external;
  80.         function f_add( op1, op2: real): real; external;
  81.         function f_sub( op1, op2: real): real; external;
  82.         function f_mult(op1, op2: real): real; external;
  83.         function f_div( op1, op2: real): real; external;
  84.         procedure sinlook( arg: integer; var sin: real); external;
  85.         procedure coslook( art: integer; var cos: real); external;
  86.         function ifloat( arg: integer): real; external;
  87.         function fltrunc( arg: real): integer; external;
  88.         function fround( arg: real): integer; external;
  89.         function fltmod (art: real): real; external;
  90.         function rsin( arg: real): real; external;
  91.         function rcos( arg: real): real; external;
  92.         function craddeg( rad: real): real; external;
  93.  
  94.     In addition, you will need to insert the follwoing statement in
  95.     your program in order to tell IBM/MS Pascal that you are working
  96.     with SHORT Precision real numbers:
  97.  
  98.         procedure mpsrqq; external;
  99.  
  100.     This procedure is internal to the PASCAL.LIB library and is linked
  101.     into your program automatically when you perform the LINK function.
  102.  
  103.  
  104.     HOW DO I USE THEM?
  105.  
  106.     1. Randomize is a procedure with no arguments. It seeds the random
  107.        number generator for the function, Random.  This is accomplished
  108.        by accessing the system clock or timer.
  109.  
  110.        Use:
  111.  
  112.             randomize;
  113.  
  114.        That's all there is to that one.
  115.  
  116.  
  117.  
  118.     2. Random is a function that returns a random integer.
  119.   
  120.        Use:
  121.    
  122.             y := random(a);
  123.  
  124.           or
  125.  
  126.             if ( random(a) > 50 ) then ........
  127.  
  128.         'a' must be an integer and random (a) will return a random
  129.         integer such that
  130.  
  131.                       0 < random(a) < a.
  132.  
  133.     
  134.      3. F_add is a function that performs a single precision floating point
  135.         add of two real numbers returning their real sum.
  136.  
  137.         Use:
  138.  
  139.             y := f_add (a, b);
  140.  
  141.         Adds 'b' to 'a' and returns their sum in y.
  142.  
  143.  
  144.      4. F_sub is the same as f_add, except for,
  145.  
  146.             y := f_sub (a, b);
  147.  
  148.         'b' is subtracted FROM 'a' and the difference is stored in 'y'.
  149.  
  150.  
  151.      5. F_mult is a function that performs a single precision floating 
  152.         point multiplication of two real numbers returning their real prod-
  153.         duct.
  154.  
  155.         Use:
  156.  
  157.             y := f_mult(a, b);
  158.  
  159.         'a' is multiplied by 'b' and the product is stored in 'y'. I might
  160.         add that these functions can be nested.  For example:
  161.  
  162.             z := f_add ( f_mult ( a, b ), c );
  163.  
  164.         is completely valid, since f_mult ( a, b ) is a real number and we
  165.         presume that so is 'c'.
  166.  
  167.  
  168.  
  169.      6. F_div is the floating point division function where if,
  170.  
  171.             y := f_div (a, b);
  172.  
  173.         then 'a' is divided BY 'b' and the quotient is stored in 'y'.  In
  174.         this case, 'a' is the dividend and 'b' is the divisor.  Division 
  175.         by zero returns a zero, by the way.
  176.  
  177.      
  178.      7. Sinlook is a procedure that returns a real number which is the
  179.         trignometric sine of an integer number of degrees.  PASLIB.OBJ
  180.         contains a sine/cosine table of the real sine of integer degrees.
  181.         It can very quickly determine the sine of a number by performing
  182.         a binary search on this table.
  183.  
  184.         Use:
  185.  
  186.              sinlook (a , b);
  187.  
  188.         where 'a' is the integer representation of the number of degrees
  189.         and the sine of 'a' is returned in the real variable, 'b'. (Note
  190.         that while 'a' may be a literal, 'b' MUST be a variable)  For
  191.         example:
  192.  
  193.              sinlook (30, b);
  194.  
  195.         returns the sine of 30 degrees as a real variable in 'b'.
  196.  
  197.      
  198.      8. Coslook is the same as sinlook except that it returns the cosine
  199.         in the second variable.  Thus,
  200.  
  201.              coslook (45, x);
  202.  
  203.         places the cosine of 45 degrees in the real variable, 'x'.
  204.  
  205.  
  206.      9. Ifloat is a function which creates a real number out of an integer.
  207.         Though you can accomplish this with a simple assignment statement in
  208.         Pascal, Ifloat performs it much, much faster.
  209.  
  210.         Use:
  211.  
  212.              y := ifloat (30);
  213.  
  214.         creates the internal floating point representation of '30' and puts it
  215.         in the real variable, 'y'.  It is included primarily for speed.
  216.  
  217.  
  218.  
  219.     10. Fltrunc takes a real number and essentially throws away the fractio-
  220.         nal portion of the number, yielding an integer.  It is a function.
  221.  
  222.         Use:
  223.  
  224.              j := fltrunc (z);
  225.  
  226.         takes the floating point number in 'z' and truncates the fractional
  227.         portion and stores the resulting integer in 'j'.
  228.  
  229.  
  230.     11. The Fround function is similar to fltrunc, except the resulting in-
  231.         teger is 'rounded'.  In decimal terms this is equivalent to rounding
  232.         32.7 up to 33, whereas, 32.1 would be 32.
  233.  
  234.         Use:
  235.  
  236.              i := fround(y);
  237.  
  238.         The real number in 'y' would be rounded to an integer and placed in
  239.         'y'.
  240.  
  241.  
  242.     12. The function, fltmod, returns the fractonal portion of a real number,
  243.         throwing away the integral portion.  In decimal terms, this is like 
  244.         creating 0.333 from 8.333.  It's sort of the inverse of fltrunc.
  245.  
  246.         Use:
  247.  
  248.              r := fltmod ( s );
  249.  
  250.         and the fractional portion of the real variable, 's', will be re-
  251.         turned in the real variable, 'r'.
  252.  
  253.  
  254.     13. Rsin is what we are used to seeing in a sine function.  It returns 
  255.         the sine of a real number representing radians, of course, as a real
  256.         number.
  257.  
  258.         Use:
  259.  
  260.              y := rsin ( z );
  261.  
  262.         where the real variable, 'z', contains the angle in radians, and we
  263.         get the sine of that angle in the real variable, 'y'.  The process
  264.         used is that of table lookup (binary search) and interpolation be-
  265.         tween the two angles in degrees that 'z' is between.
  266.  
  267.    
  268.     14. Rcos is the same as rsin, except the cosine of the angle is returned.
  269.  
  270.         Thus,
  271.  
  272.              x := rcos ( y );
  273.  
  274.  
  275.  
  276.     15. Craddeg is a function that simply converts radians to degrees, so,
  277.  
  278.              z := craddeg (r);
  279.  
  280.         converts the real number in 'r' from radians to degrees and stores 
  281.         the result in the real variable, 'z'.
  282.  
  283.      
  284.     That's how to use it in IBM/MS Pascal in so far as the programming is
  285.     concerned.  The remaining step is to get PASCLIB physically accessible
  286.     to your program.  This is accomplished by LINKing PASCLIB.OBJ to your
  287.     program.  The simplest way to do this is shown by example.  If your
  288.     program, containing PASCLIB.INC and PASCLIB function/procedure usage,
  289.     is called "MYPROG.PAS", then after a successfuly compilation through
  290.     PAS1 and PAS2, to obtain MYPROG.OBJ, you would enter the following
  291.     command at the DOS prompt:
  292.  
  293.         link myprog+pasclib;
  294.  
  295.     The result will be the executable progam, MYPROG.EXE.  The link process
  296.     can, of course, be more complicated for the user with additional Pascal
  297.     modules or librarys, but he hardly needs instructions.  Other users,
  298.     with access to an appropriate LIB.EXE or LIB.COM program, may choose to
  299.     create PASCLIB.LIB or include PASCLIB.OBJ into PASCAL.LIB (as I  have
  300.     done).
  301.  
  302.  
  303.     TECHNICAL INFORMATION
  304.  
  305.     The floating point format used in the PASCLIB.OBJ module is directly
  306.     compatible with that used in IBM/MS Pascal short precision.  It is
  307.     32 bit, sign in the high order bit followed by the characteristic
  308.     (exponent) and mantissa (fraction).  See the description in your
  309.     IBM/MS Pascal documentation around the description of MPSRQQ.
  310.  
  311.  
  312.     For you Assembler Language programmers (you probably don't need much 
  313.     instruction), I will remind you of several considerations.  To use
  314.     the functions/procedures in PASCLIB.OBJ, you
  315.  
  316.     1. Must include an EXTERN Compiler directive in the segment calling
  317.        PASCLIB.OBJ routines, or if external to the seqment the function/
  318.        procedure namse called must be declared in an ASSIGN statement.
  319.        The following names were declared as PUBLIC within PASCLIB:
  320.  
  321.        RANDOMIZE, RANDOM, F_ADD, F_SUB, F_MULT, F_DIV, SINLOOK, COSLOOK,
  322.        IFLOAT, FLTRUNC, FROUND, FLTMOD, RSIN, RCOS, CRADDEG
  323.  
  324.        If you are calling F_MULT and RSIN in your program, you shold
  325.        include the following statement within the segment performing
  326.        the calls:
  327.  
  328.        EXTERN F_MULT:FAR, RSIN:FAR
  329.  
  330.     2. Must use a FAR CALL to interface to the modules, thus
  331.  
  332.        CALL FAR PTR F_MULT
  333.   
  334.        or
  335.  
  336.        CALL FAR PTR RSIN
  337.  
  338.     3. Must be familiar with the CALLing linkage for interfacing
  339.        Pascal programs to Assembler language subroutines.  A reminder:
  340.  
  341.        Parameters are passed and returned in several different ways
  342.        using IBM/MS Pascal.
  343.  
  344.        In the case of "call by name" (where a VAR was included in the
  345.        definition), the ADDRESS of the variable is pushed on the stack
  346.        prior to the call.  In the case of "call by value" (No VAR in
  347.        the definition), the actual parameter, itself, is pushed on the
  348.        stack.  For floating point (real) values, the low-order word is
  349.        pushed first followed by the high order byte (for call by value).
  350.        For call by name, the address of the low-order byte is pushed on
  351.        the stack.
  352.  
  353.        For procedures (SINLOOK and COSLOOK), the result is returned in
  354.        the return variable (in this case, the second variable).
  355.  
  356.        For functions, the result is returned in the last address pushed
  357.        on the stack prior to the CALL, and the address of the answer
  358.        is returned in the AX register.
  359.  
  360.        Remember that values/addresses must be pushed on the stack in
  361.        the sequence that they appear in the Pascal definitions, from
  362.        left to right, prior to the CALL.
  363.  
  364.      
  365.     I hope you benefit from using PASCLIB, and I will appreciate any
  366.     feedback (good or bad) about PASCLIB.  I will attempt to fix any
  367.     bugs that crop up, but can only gurantee a "best effort".  I have
  368.     found that it's accuracy is essentially the same as that of the
  369.     BASICA Interpreter and its speed is "Out of Sight".  Have fun!
  370.